﻿using System.Text;

namespace PermissionAuthenticationDemo.Config
{
    public class CreateAuthCode
    {
        public static string GenerateCaptcha(int length)
        {
            //定义字符集，包含数字和字母
            const string chars = "ABCDEFGHIJKLMNOPQRSTUVWSYZabcdefghijklmnopqrstuvwsyz0123456789";
            //创建一个随机数生成器
            Random random = new Random();
            //使用StringBuilder来构建验证码
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < length; i++)
            {
                //从字符集中随机选择一个字符
                int index = random.Next(chars.Length);
                char randomChar = chars[index];
                stringBuilder.Append(randomChar);
            }
            return stringBuilder.ToString();
        }
    }
}
